//
// Created by LiuYou on 2021/8/20.
//

#include <exception>
#include "Locker.hpp"

Locker::Locker() {
    if (pthread_mutex_init( &mutex, nullptr ) != 0) {
        throw std::exception();
    }
}

Locker::~Locker() {
    pthread_mutex_destroy( &mutex );
}

bool Locker::lock() {
    return pthread_mutex_lock( &mutex ) == 0;
}

bool Locker::unlock() {
    return pthread_mutex_unlock( &mutex ) == 0;
}
